#include "TryExcept.h"
#include "IVisitor.h"

TryExcept::TryExcept(const StmtTypeList& body, const ExcepthandlerTypeList& handlers, const suiteTypePtr& orelse, int nodeId):
    stmtType(nodeId),
    _body(body),
    _handlers(handlers),
    _orelse(orelse)
{
}
    
TryExcept::~TryExcept()
{
    _body.clear();_handlers.clear();
}
    
Ast::AstTypes TryExcept::type() const
{
    return Ast::TryExcept;
}
    

StmtTypeList TryExcept::body()
{
    return _body;
}

void TryExcept::setBody(const StmtTypeList& body)
{
    _body = body;
}

ExcepthandlerTypeList TryExcept::handlers()
{
    return _handlers;
}

void TryExcept::setHandlers(const ExcepthandlerTypeList& handlers)
{
    _handlers = handlers;
}

suiteTypePtr TryExcept::orelse()
{
    return _orelse;
}

void TryExcept::setOrelse(const suiteTypePtr& orelse)
{
    _orelse = orelse;
}

    
QString TryExcept::toString() const
{
    return QString("TryExcept[body=%1, handlers=%2, orelse=%3]").
                arg(_body.toString()).
                arg(_handlers.toString()).
                arg(_orelse ? _orelse->toString():"");
}
    
void TryExcept::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitTryExcept(node.dynamicCast<TryExcept>());
}
    
void TryExcept::traverse(IVisitor* visitor)
{
    _body.traverse(visitor);
    _handlers.traverse(visitor);
    if (_orelse != NULL)
        _orelse->accept(visitor, _orelse);
}